<template>
  <div class="reply-comment">
    <!-- 导航栏 -->
    <van-nav-bar :title="`${comment.reply_count}条回复`">
      <van-icon
        slot="left"
        name="cross"
        @click="$emit('click-close')"
      />
    </van-nav-bar>
    <!-- /导航栏 -->

    <!-- 当前评论项 -->
    <item-comment :comment="comment"></item-comment>
    <!-- /当前评论项 -->

    <!-- 评论的回复列表 -->
    <van-cell title="所有回复"
     />
    <article-comment
      :source="comment.com_id"
      :type="'c'"
      :list="commentList"
    ></article-comment>
    <!-- /评论的回复列表 -->
    <!-- 底部 -->
    <div class="article-bottom">
      <van-button
        class="comment-btn"
        type="default"
        round
        size="small"
        @click="isPostShow = true"
      >写评论</van-button>
    </div>
    <van-popup
      v-model="isPostShow"
      position="bottom"
    >
    <post-comment
     :target="comment.com_id"
     :article-id="articleId"
     @post-success="onPostSuccess"></post-comment>
    </van-popup>
    <!-- /底部 -->
  </div>
</template>

<script>
import ArticleComment from './article-comment.vue'
import ItemComment from './item-comment.vue'
import PostComment from './post-comment'
import { getUserInfo } from '@/api/user'
export default {
  name: 'ReplyComment',
  components: {
    ItemComment,
    ArticleComment,
    PostComment
  },
  props: {
    comment: {
      type: Object,
      require: true
    },
    articleId: {
      type: [Number, String, Object],
      required: true
    }
  },
  data () {
    return {
      isPostShow: false,
      commentList: [] // 评论的回复列表
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    async onPostSuccess (comment) {
      const { content } = comment
      const comId = comment.comId
      console.log(comId)
      const { data } = await getUserInfo()
      const newMessage = {
        com_id: comId.com_id,
        aut_id: data.data.id,
        content,
        is_top: 0,
        aut_name: data.data.name,
        pubdate: Date.now(),
        reply_count: 0,
        like_count: 0,
        is_liking: false
      }
      this.commentList.unshift(newMessage)
      this.comment.reply_count++
      this.isPostShow = false
    }
  }
}
</script>

<style lang="less" scoped>
.article-bottom {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-sizing: border-box;
    height: 44px;
    border-top: 1px solid #d8d8d8;
    background-color: #fff;
    .comment-btn{
      width: 141px;
      height: 30px;
      border: 1px solid #eeeeee;
      font-size: 15px;
      line-height: 23px;
      color: #a7a7a7;
    }
}
</style>
